﻿using System;
using System.Windows.Forms;
using LyricTrackerPlugin;
using LyricTrackerPlugin.Properties;
using Slippor.Douban.Radio.Assist;

namespace LyricTrackerUserControl
{
    public partial class ConfigControl : UserControl
    {
        public ConfigControl()
        {
            InitializeComponent();
            InitializeConfigs();
            HotKey.InitHotKeyTextBox(textBoxShortCut);
        }

        private void InitializeConfigs()
        {
            textBoxShortCut.Text = _settings.ShortCutKey;
            fontDialog.Font = _settings.Font;
            fontDialog.Color = _settings.Color;
            labelExample.Font = _settings.Font;
            labelExample.ForeColor = _settings.Color;
        }

        private void ConfirmConfigs()
        {
            _settings.ShortCutKey = textBoxShortCut.Text;
            _settings.Font = labelExample.Font;
            _settings.Color = labelExample.ForeColor;
            _settings.Save();
        }

        private Settings _settings = LyricTrackerConfig.SettingManager.Settings as Settings;

        public event EventHandler Closed;

        private DialogResult _dialogResult = DialogResult.None;
        public DialogResult DialogResult
        {
            get { return _dialogResult; }
        }

        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            ConfirmConfigs();
            _dialogResult = DialogResult.OK;
            if (Closed != null)
            {
                Closed(sender, e);
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            _dialogResult = DialogResult.Cancel;
            if (Closed != null)
            {
                Closed(sender, e);
            }
        }

        private void buttonReset_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定重置？", "提示", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                _settings.Reset();
                _settings.Save();
                InitializeConfigs();
            }
        }

        private void buttonChoose_Click(object sender, EventArgs e)
        {
            var result = fontDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                labelExample.Font = fontDialog.Font;
                labelExample.ForeColor = fontDialog.Color;
            }
        }
    }
}
